﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using MySql.Data;
using MySql.Data.MySqlClient;
using Mapeo;
using NHibernate;

namespace DAL
{
    public class ReporteComprobanteVenta_DAL:Controlador
    {
        public DataTable DATA_ComprobanteVenta_Listado(String idComprobanteVenta)
        {
            using (ISession Sesion = m_SessionFactory.OpenSession())
            {
                using (ITransaction Trans = Sesion.BeginTransaction())
                {
                    MySqlCommand SqlCmd = new MySqlCommand();
                    SqlCmd.Connection = (MySqlConnection)Sesion.Connection;
                    Trans.Enlist(SqlCmd);
                    SqlCmd.CommandText = "Cursor_ComprobanteVenta";
                    SqlCmd.CommandType = System.Data.CommandType.StoredProcedure;
                    SqlCmd.Parameters.AddWithValue("@idComprobanteVena", idComprobanteVenta);
                    SqlCmd.ExecuteNonQuery();
                    MySqlDataAdapter da = new MySqlDataAdapter(SqlCmd);
                    DataTable dt = new DataTable();
                    da.Fill(dt);
                    Trans.Commit();
                    return dt;
                }
            }
        }

        //PARA reporte con FILTROS DE CONCEPTOS EN COMPROVANTE VENTA:
        public DataTable ReporteComprovanteVenta(String nombre, string concepto, DateTime fecInicio, DateTime fecFin, string tipoDoc, Int32 anulado)
        {
            using (ISession Sesion = m_SessionFactory.OpenSession())
            {
                using (ITransaction Trans = Sesion.BeginTransaction())
                {
                    MySqlCommand SqlCmd = new MySqlCommand();
                    SqlCmd.Connection = (MySqlConnection)Sesion.Connection;
                    Trans.Enlist(SqlCmd);
                    SqlCmd.CommandText = "sp_Reporte_ComprobanteVenta";
                    SqlCmd.CommandType = System.Data.CommandType.StoredProcedure;
                    SqlCmd.Parameters.AddWithValue("@inNombre", nombre);
                    SqlCmd.Parameters.AddWithValue("@inConcepto", concepto);
                    SqlCmd.Parameters.AddWithValue("@inFechaInicio", fecInicio.Date);
                    SqlCmd.Parameters.AddWithValue("@inFechaFinal", fecFin.Date);
                    SqlCmd.Parameters.AddWithValue("@inTipoDoc", tipoDoc);
                    SqlCmd.Parameters.AddWithValue("@inAnulado", anulado);

                    SqlCmd.ExecuteNonQuery();
                    MySqlDataAdapter da = new MySqlDataAdapter(SqlCmd);
                    DataTable dt = new DataTable();
                    da.Fill(dt);
                    Trans.Commit();
                    return dt;
                }
            }
        }



        public DataTable ReporteAlumnosQuePagaronMatricula(String especialidad, String alumno)
        {
            using (ISession Sesion = m_SessionFactory.OpenSession())
            {
                using (ITransaction Trans = Sesion.BeginTransaction())
                {
                    MySqlCommand SqlCmd = new MySqlCommand();
                    SqlCmd.Connection = (MySqlConnection)Sesion.Connection;
                    Trans.Enlist(SqlCmd);
                    SqlCmd.CommandText = "sp_Reporte_AlumnosQuePagaronMatricula";
                    SqlCmd.CommandType = System.Data.CommandType.StoredProcedure;
                    SqlCmd.Parameters.AddWithValue("@in_Especialidad", especialidad);
                    SqlCmd.Parameters.AddWithValue("@in_Alumno", alumno);
                    SqlCmd.ExecuteNonQuery();
                    MySqlDataAdapter da = new MySqlDataAdapter(SqlCmd);
                    DataTable dt = new DataTable();
                    da.Fill(dt);
                    Trans.Commit();
                    return dt;
                }
            }
        }


        public DataTable ReporteAlumnosQuePagaronMatricula2(String especialidad, String alumno)
        {
            using (ISession Sesion = m_SessionFactory.OpenSession())
            {
                using (ITransaction Trans = Sesion.BeginTransaction())
                {
                    MySqlCommand SqlCmd = new MySqlCommand();
                    SqlCmd.Connection = (MySqlConnection)Sesion.Connection;
                    Trans.Enlist(SqlCmd);
                    SqlCmd.CommandText = "sp_Reporte_AlumnosQuePagaronMatricula2";
                    SqlCmd.CommandType = System.Data.CommandType.StoredProcedure;
                    SqlCmd.Parameters.AddWithValue("@in_Especialidad", especialidad);
                    SqlCmd.Parameters.AddWithValue("@in_Alumno", alumno);
                    SqlCmd.ExecuteNonQuery();
                    MySqlDataAdapter da = new MySqlDataAdapter(SqlCmd);
                    DataTable dt = new DataTable();
                    da.Fill(dt);
                    Trans.Commit();
                    return dt;
                }
            }
        }
 
    }
}
